package com.gwl.circle.api.config;

import com.gwl.circle.common.config.SystemConfig;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;


public class OpenFeignConfig implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //1.获取当前的请求对象
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request=attributes.getRequest();
        String token=request.getHeader(SystemConfig.HEADER_TOKEN);
        //2.把需要传递的请求消息头的的内容，设置到OpenFeign的请求对象上
        requestTemplate.header(SystemConfig.HEADER_TOKEN,token);
    }
}
